
\begin{frame}
\frametitle{SciPy}
\reference{
More info: \url{http://www.scipy.org/}
}
\overlayicon{Logo/scipy}
\begin{itemize}
  \item Contains many scientific Python modules built on top of NumPy.
  \item Most interesting for computer vision work are
  \begin{description}
   \item[\href{http://docs.scipy.org/doc/scipy/reference/tutorial/ndimage.html}{ndimage}]
         Multi-dimensional image processing
   \item[\href{http://docs.scipy.org/doc/scipy/reference/tutorial/linalg.html}{linalg}]
         Linear Algebra (extends numpy.linalg)
   \item[\href{http://docs.scipy.org/doc/scipy/reference/tutorial/fftpack.html}{fftpack}]
         Fourier Transforms
   \item[\href{http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html}{optimize}]
         Optimization
   \item[\href{http://docs.scipy.org/doc/scipy/reference/tutorial/io.html}{io}]
         File IO (read/write MATLAB files)
  \end{description}
  \pause
  \item In this tutorial, we are only going to scratch the surface of what is contained in these libraries with a few examples.
\end{itemize}
\end{frame}


\begin{frame}
\frametitle{SciKits}
\reference{
More info: \url{http://scikits.appspot.com/}
}
\overlayicon{Logo/scipy}
\begin{itemize}
  \item There are also many add-on toolkits for SciPy, collectively called SciKits
  \item Most interesting for computer vision work are
  \begin{description}
   \item[\href{http://scikits.appspot.com/scikits-image}{scikits-image}]
         Image Processing
   \item[\href{http://scikits.appspot.com/scikit-learn}{scikits-learn}]
         Machine Learning and Data Mining
   \item[\href{http://scikits.appspot.com/ann}{ann}]
         Approximate Nearest Neighbor library wrapper
   \item[\href{http://scikits.appspot.com/mlabwrap}{mlabwrap}]
         Call MATLAB from Python
  \end{description}
\end{itemize}
\end{frame}


\begin{frame}
\frametitle{SciPy Central}
\reference{
More info: \url{http://scipy-central.org/}
}
\overlayicon{Logo/scipy}
\begin{itemize}
  \item Looking for an equivalent to MATLAB Central for sharing snippets of scientific Python code?
  \pause
  \item Try SciPy Central (\href{http://scipy-central.org/}{scipy-central.org})
  \pause
  \item It's not as extensive as MATLAB Central, but it's fairly new.
\end{itemize}
\end{frame}


\begin{frame}
\frametitle{SciPy By Example}
\overlayicon{Logo/scipy}
\begin{itemize}
  \item Let's work through an example of writting a Canny edge detector.
  \item This is not a very efficient implementation of Canny edge detection.
  \item The goal is to illustrates some SciPy and Numpy functionality.
  \item Open the file Examples/scipy\_canny.py
\end{itemize}
\end{frame}


\begin{frame}[fragile]
\frametitle{SciPy By Example -- Importing}
\overlayicon{Logo/scipy}
\begin{itemize}
  \item First import what we need: NumPy and and NDImage from SciPy.
  \item These modules are imported to abreviated names \lstpy{np} and \lstpy{ndi}.
  \item Note that the constant \lstpy{pi} (i.e.\ $\pi$) is imported into the
        global namespace to make math expressions easier to follow.
\end{itemize}
\lstset{title=Examples/scipy\_canny.py}
\lstlistingwithnumber{4}{6}{Examples/scipy_canny.py}
\end{frame}


\begin{frame}[fragile]
\frametitle{SciPy By Example -- Main}
\overlayicon{Logo/scipy}
\begin{itemize}
  \item Now look at the end of the file.
\end{itemize}
\lstset{title=Examples/scipy\_canny.py}
\lstlistingwithnumber{46}{51}{Examples/scipy_canny.py}
\begin{itemize}
  \item Usually all imports happen at the top of a file, but this is not required.
  \item In this example some more things are imported only when this file is run as a script.
  \item When run as a script, this code calls \lstpy{canny_edges} on the Lena image and
        displays the result in a matplotlib GUI.
  \item When imported into another module, there is no dependency on matplotlib or Lena.
\end{itemize}

\end{frame}


\begin{frame}[fragile]
\frametitle{SciPy By Example -- Result}
\overlayicon{Logo/scipy}
\begin{itemize}
  \item Calling \lstpy{imshow(lena())} would show the input image on the left.
  \item Running this script displays the image on the right.
\end{itemize}
\begin{columns}[c]
\column{0.5\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{Plots/scipy-lena}\\
Input Image
\column{0.5\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{Plots/scipy-canny-lena}\\
Canny Edges
\end{columns}
\end{frame}


\begin{frame}[fragile]
\frametitle{SciPy By Example -- Canny}
\overlayicon{Logo/scipy}
\begin{itemize}
  \item Here is the Canny edge detection code.
\end{itemize}
\lstset{title=Examples/scipy\_canny.py}
\lstlistingwithnumber{27}{43}{Examples/scipy_canny.py}
\begin{itemize}
  \item Only \lstpy{non_maximal_edge_suppression} is not provided by \lstpy{np} or \lstpy{ndi}.
\end{itemize}
\end{frame}


\begin{frame}[fragile]
\frametitle{SciPy By Example -- Gaussian Filter}
\overlayicon{Logo/scipy}
\begin{enumerate}
  \item Smooth the image with a Gaussian Filter.
  \saveenum
\end{enumerate}
\lstset{title=Examples/scipy\_canny.py}
\lstlistingwithnumber{29}{29}{Examples/scipy_canny.py}
\vspace{-1em}
\begin{columns}[c]
\column{0.5\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{Plots/scipy-lena}\\
Input Image
\column{0.5\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{Plots/scipy-gaussian-lena}\\
Gaussian Filter with $\sigma=5$
\end{columns}
\end{frame}


\begin{frame}[fragile]
\frametitle{SciPy By Example -- Sobel}
\overlayicon{Logo/scipy}
\begin{enumerate}
  \resume
  \item Sobel derivatives on smoothed image.
  \saveenum
\end{enumerate}
\vspace{-1em}
\lstset{title=Examples/scipy\_canny.py}
\lstlistingwithnumber{30}{31}{Examples/scipy_canny.py}
\vspace{-1em}
\begin{columns}[c]
\column{0.5\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{Plots/scipy-dx-lena}\\
dx -- Sobel horizontal
\column{0.5\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{Plots/scipy-dy-lena}\\
dy -- Sobel vertical
\end{columns}
\end{frame}


\begin{frame}[fragile]
\frametitle{SciPy By Example -- Gradient Mag/Orient}
\overlayicon{Logo/scipy}
\begin{enumerate}
  \resume
  \item Sobel derivatives on smoothed image.
  \saveenum
\end{enumerate}
\vspace{-1em}
\lstset{title=Examples/scipy\_canny.py}
\lstlistingwithnumber{33}{34}{Examples/scipy_canny.py}
\vspace{-1em}
\begin{columns}[c]
\column{0.5\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{Plots/scipy-grad-mag-lena}\\
Gradient Magnitude
\column{0.5\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{Plots/scipy-grad-ort-lena}\\
Gradient Orientation
\end{columns}
\end{frame}


\begin{frame}[fragile]
\frametitle{SciPy By Example -- Non-Max Suppression}
\overlayicon{Logo/scipy}
\begin{enumerate}
  \resume
  \item Non-maximal suppression (more on this later).
  \saveenum
\end{enumerate}
\vspace{-1em}
\lstset{title=Examples/scipy\_canny.py}
\lstlistingwithnumber{36}{36}{Examples/scipy_canny.py}
\vspace{-1em}
\begin{center}
\includegraphics[width=0.4\linewidth]{Plots/scipy-nonmaxsup-lena}\\
All maximimal edges (binary image)
\end{center}
\end{frame}


\begin{frame}[fragile]
\frametitle{SciPy By Example -- Threshold}
\overlayicon{Logo/scipy}
\begin{enumerate}
  \resume
  \item Apply the lower threshold
  \saveenum
\end{enumerate}
\vspace{-1em}
\lstset{title=Examples/scipy\_canny.py}
\lstlistingwithnumber{37}{37}{Examples/scipy_canny.py}
\vspace{-1em}
\begin{columns}[c]
\column{0.5\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{Plots/scipy-thresh-low-lena}\\
Low Threshold (50)
\column{0.5\textwidth}
\centering
\includegraphics[width=0.8\linewidth]{Plots/scipy-thresh-high-lena}\\
High Threshold (100)
\end{columns}
\end{frame}


\begin{frame}[fragile]
\frametitle{SciPy By Example -- Label Connected Components}
\overlayicon{Logo/scipy}
\begin{enumerate}
  \resume
  \item Label connected components using 8-neighborhood (3x3 mask of ones).
  \saveenum
\end{enumerate}
\vspace{-1em}
\lstset{title=Examples/scipy\_canny.py}
\lstlistingwithnumber{39}{39}{Examples/scipy_canny.py}
\vspace{-1em}
\begin{center}
\includegraphics[width=0.4\linewidth]{Plots/scipy-label-lena}\\
Connected edges with random colors
\end{center}
\end{frame}


\begin{frame}[fragile]
\frametitle{SciPy By Example -- Hysteresis }
\overlayicon{Logo/scipy}
\begin{enumerate}
  \resume
  \item Remove connected edges not containing a value above the high threshold.
  \saveenum
\end{enumerate}
\vspace{-1em}
\lstset{title=Examples/scipy\_canny.py}
\lstlistingwithnumber{40}{42}{Examples/scipy_canny.py}
\vspace{-1em}
\begin{columns}[c]
\column{0.3\textwidth}
\centering
\includegraphics[width=\linewidth]{Plots/scipy-thresh-low-lena}\\
Low Threshold (50)
\column{0.3\textwidth}
\centering
\includegraphics[width=\linewidth]{Plots/scipy-canny-lena}\\
Hysteresis
\column{0.3\textwidth}
\centering
\includegraphics[width=\linewidth]{Plots/scipy-thresh-high-lena}\\
High Threshold (100)
\end{columns}
\end{frame}


\begin{frame}[fragile]
\frametitle{SciPy By Example -- Non-Max Suppression }
\overlayicon{Logo/scipy}
\begin{itemize}
  \item Non-Maximal Suppression of edges produces a binary edge map.
  \item Gradient magnitude is a maximum in the direction normal to an edge.
\end{itemize}
\vspace{-1em}
\lstset{title=Examples/scipy\_canny.py}
\lstlistingwithnumber{9}{24}{Examples/scipy_canny.py}
\end{frame}
